package cn.maiyar.mybatis.service.impl;

import cn.maiyar.common.entity.BaseEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.maiyar.common.constant.CommonConstant;
import cn.maiyar.mybatis.service.BaseService;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 业务封装基础类
 *
 * @author c.c
 */
@Validated
public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> extends ServiceImpl<M, T> implements BaseService<T> {

    @Override
    public boolean save(T entity) {
        if (entity.getStatus() == null) {
            entity.setStatus(CommonConstant.DB_STATUS_NORMAL);
        }
        Integer isDeleted = entity.getIsDeleted();
        if (isDeleted == null) {
            entity.setIsDeleted(CommonConstant.DB_NOT_DELETED);
        }
        return super.save(entity);
    }

    @Override
    public boolean updateById(T entity) {
        return super.updateById(entity);
    }

    @Override
    public boolean deleteLogic(@NotEmpty List<String> ids) {
        return super.removeByIds(ids);
    }
}
